package com.AIDS.AIDSweeper.server.model;

import java.util.*;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
public class Game {
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;
	
	@Persistent
	private String status;
	
	@Persistent
	private int networkResolution;
	
	@Persistent
	private int mineRadius;
	
	@Persistent
	private Date startTime;
	
	@Persistent
	private long duration;
	
	@Persistent
	private String gamePassword;
	
	@Persistent
	private String boundaries;
	
	@Persistent
	private int maxMines;
	
	@Persistent
	private int defuseDist;
	
	@Persistent
	private int penalityRadius;
	
	@Persistent
	private boolean mineDirty;
	
	@Persistent(mappedBy="myGame")
	private List<Gamer> Gamers;
	
	@Persistent(mappedBy="inGame")
	private List<Mine> Mines;

	public Game(String status, int networkResolution, int mineRadius,
			Date startTime, long duration, String gamePassword,
			String boundaries, int maxMines, int defuseDist, int penalityRadius,boolean mineDirty) {
		super();
		this.status = status;
		this.networkResolution = networkResolution;
		this.mineRadius = mineRadius;
		this.startTime = startTime;
		this.duration = duration;
		this.gamePassword = gamePassword;
		this.boundaries = boundaries;
		this.maxMines = maxMines;
		this.defuseDist = defuseDist;
		this.penalityRadius = penalityRadius;
		this.mineDirty = mineDirty;
		Gamers = new ArrayList<Gamer>();
		Mines = new ArrayList<Mine>();
	}

	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public int getNetworkResolution() {
		return networkResolution;
	}

	public void setNetworkResolution(int networkResolution) {
		this.networkResolution = networkResolution;
	}

	public int getMineRadius() {
		return mineRadius;
	}

	public void setMineRadius(int mineRadius) {
		this.mineRadius = mineRadius;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public long getDuration() {
		return duration;
	}

	public void setDuration(long duration) {
		this.duration = duration;
	}

	public String getGamePassword() {
		return gamePassword;
	}

	public void setGamePassword(String gamePassword) {
		this.gamePassword = gamePassword;
	}

	public String getBoundaries() {
		return boundaries;
	}

	public void setBoundaries(String boundaries) {
		this.boundaries = boundaries;
	}

	public int getMaxMines() {
		return maxMines;
	}

	public void setMaxMines(int maxMines) {
		this.maxMines = maxMines;
	}

	public int getDefuseDist() {
		return defuseDist;
	}

	public void setDefuseDist(int defuseDist) {
		this.defuseDist = defuseDist;
	}

	public int getPenalityRadius() {
		return penalityRadius;
	}

	public void setPenalityRadius(int penalityRadius) {
		this.penalityRadius = penalityRadius;
	}

	public void addGamer(Gamer newGamer) {
		Gamers.add(newGamer);
	}
	
	public void removeGamer(Gamer oldGamer) {
		Gamers.remove(oldGamer);
	}
	
	public void addActiveMine(Mine newMine) {
		Mines.add(newMine);
	}
	
	public void removeActiveMine(Mine oldMine) {
		Mines.remove(oldMine);
	}

	public boolean isMineDirty() {
		return mineDirty;
	}

	public void setMineDirty(boolean mineDirty) {
		this.mineDirty = mineDirty;
	}

	public List<Gamer> getGamers() {
		return Gamers;
	}

	public void setGamers(List<Gamer> gamers) {
		Gamers = gamers;
	}

	public List<Mine> getMines() {
		return Mines;
	}

	public void setMines(List<Mine> mines) {
		Mines = mines;
	}

	@Override
	public String toString() {
		return "<id>"+KeyFactory.keyToString(id)+"</id>\n<status>"+status+"</status>\n<networkResolution>"+networkResolution+"</networkResolution>" +
				"\n<mineRadius>"+mineRadius+"</mineRadius>\n<startTime>"+startTime+"</startTime>" +
				"\n<duration>"+duration+"</duration>\n<boundaries>"+boundaries+"</boundaries>\n<maxMines>"+maxMines+"</maxMines>" +
				"\n<defuseDist>"+defuseDist+"</defuseDist>\n<penalityRadius>"+penalityRadius+"</penalityRadius>" +
				"\n<mineDirty>"+mineDirty+"</mineDirty>";
	}
	
}